﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using ScrumPilot.Helpers;
using ScrumPilot.TFSHelpers;

namespace ScrumPilot.Domain.Models
{
    public class SprintBase
    {
        [Key]
        public int ID { get; set; }
        [Display(Name = "Name")]
        public String Name { get; set; }
        [Display(Name = "State")]
        [Range(0, 3)]
        [EnumDataType(typeof(SprintState))]
        public SprintState State { get; set; }
        [Display(Name = "Start Date")]
        [DataType(DataType.Date)]
        public Nullable<DateTime> StartDate { get; set; }
        [Display(Name = "End Date")]
        [DataType(DataType.Date)]
        public Nullable<DateTime> EndDate { get; set; }
    }

    public class Sprint : SprintBase
    {
        [Display(Name = "Description")]
        public String Description { get; set; }
        [Display(Name = "Retrospective")]
        public String Retrospective { get; set; }

        public Dictionary<int, string> StateList
        {
            get
            {
                return new Dictionary<int, string>
                             {
                                {(int) SprintState.Current, "Current"},
                                {(int) SprintState.Next, "Next"},
                                {(int) SprintState.WaitingRetrospective, "Waiting Retrospective"},
                                {(int) SprintState.Close, "Close"}
                             };

            }
        }
        /* public SelectList StateList
         {
             get
             {
                 var sl = new SelectList(new Dictionary<int, string>
                                  {
                                     {(int) SprintState.Current, "Current"},
                                     {(int) SprintState.Next, "Next"},
                                     {(int) SprintState.WaitingRetrospective, "Waiting Retrospective"},
                                     {(int) SprintState.Close, "Close"}
                                  }, "key", "value", (int)this.State);
                 return sl;
             }
         }*/
    }

    public class SprintForTable : SprintBase
    {
        [Display(Name = "Iteration define in")]
        public String Iterations { get; set; }
    }

    public class SprintIteration : Iteration
    {
        public Boolean Selected { get; set; }
    }

     public class SprintDefinition
     {
         public int ID { get; set; }
         public String Name { get; set; }
         public DateTime StartDate { get; set; }
         public DateTime EndDate { get; set; }

         private int _workingDays = -1;
         public int WorkingDays
         {
             get
             {
                 if (_workingDays == -1)
                     _workingDays = DateTimeHelpers.GetWorkDays(this.StartDate, this.EndDate);
                 return this._workingDays;
             }
         }

         private int _remainDays = -1;
         public int RemainDays
         {
             get
             {
                 if (_remainDays == -1)
                     _remainDays = DateTimeHelpers.GetWorkDays(DateTime.UtcNow, this.EndDate);
                 return this._remainDays;
             }
         }
     }
}
